<?php 
session_start();
define("CCTRLNAME", "slider");
class slider extends CI_Controller  {

        /**
        * Index Page for this controller.
        *
        * Maps to the following URL
        * 		http://example.com/index.php/welcome
        *	- or -  
        * 		http://example.com/index.php/welcome/index
        *	- or -
        * Since this controller is set as the default controller in 
        * config/routes.php, it's displayed at http://example.com/
        *
        * So any other public methods not prefixed with an underscore will
        * map to /index.php/welcome/<method_name>
        * @see http://codeigniter.com/user_guide/general/urls.html
        */
       private $_configs = null;
       function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('javascript');
            $this->load->library('smarty3','','smarty');
            $this->load->model('admin-planners/gallery_model','my_model');
            $this->load->model('admin-planners/setting_model','setting_model');
            include APPPATH . 'libraries/defu.php';
        }
        
      
        function index(){
            if(!checkAuthority(CCTRLNAME)){
                $this->smarty
                        ->assign('_SESSION', $_SESSION)
                        ->display("sys/04_access_denied");
                return;
            }
            $Data=null;
            $Data["tab_config"]["tabs"]=array(
                "slider"   =>array(
                    "display"=>"Slider"
                    ,"link"=>  base_url("admin-planners/gallery/slider")
                    )
            );
            $Data["tab_config"]["tabindex"]="slider";
            $obj=$this->my_model->get(1);
            if(count($obj)>0)$Data["OBJ"]=$obj[0];
            $this->smarty
                    ->assign('_SESSION', $_SESSION)
                    ->assign('Data', $Data)
                    ->display("admin-planners/gallery/slider");
        }
        function Save(){
            $vlows=array("\\\"","\\'");
            $vals=array("\"","'");
            
            $msgs=array();
            if( (!isset($_POST["AlbumName"])) || $_POST["AlbumName"]==""){
                $msgs[]="AlbumName Name does not empty.";
            }
            if( (!isset($_POST["Album"]) || count($_POST["Album"])==0)){
                $msgs[]="Album does not empty.";
            }
            if(count($msgs)>0){
                $code=-44;
                $msg="";
                foreach ($msgs as $m){
                    $msg.="$m<br/>";
                }
            }else{
                
                $Params=array(
                    "AlbumName"         =>$_POST["AlbumName"],
                    "Amount"        =>  count($_POST["Album"]),
                    "Images"        => json_encode($_POST["Album"]),
                    "Alias"         =>  convertUrl($_POST["AlbumName"]),
                );
                $ip = getIP();
                if(isset($_POST["ID"]) && $_POST["ID"]!=""){
                    $ID=$_POST["ID"];
                    //$Params["Log"] = "    IP : $ip \n    Action : Update \n    RowID : $ID";
                    if($this->my_model->update(1,$Params)){
                        //$this->log_model->insert(array("Table" => "Video","RowID"=>$Params["VideoID"], "Action" => "Update", "Log" => $VideoParams["Log"]));
                        $code=1;
                        $msg="Success. Item have been updated.";
                    }else{
                        $code=-1;
                        $msg="Fail. Cant update this Item.";
                    }
                }else{
                    //$Params["Log"]="    IP : $ip \n    Action : Insert ";
                    if($this->my_model->insert($Params)){
                        //$this->log_model->insert(array("Table"=>"Video","Action"=>"Insert","Log"=>$VideoParams["Log"]));
                        $code=1;
                        $msg="Success. Item have been added to database.";
                    }else{
                        $code=-1;
                        $msg="Fail. Cant insert Item to database.";
                    }
                }
            }
            echo json_encode(array("code"=>$code,"msg"=>$msg));
        }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */